#ifndef REQUESTDISPATCHER_H
#define REQUESTDISPATCHER_H

#include <QObject>
#include <exception>
#include <QtGui/QApplication>
#include <Windows.h>
#include "wscrequesthandler.h"
#include "wscdummyperson.h"
#include "wscaircraftsjson.h"
#include "wscaircraftshtmloverview.h"
#include "wscaircraftkmlwaypoints.h"

namespace FsxWebService {

//! Central handler, decides which handler to call
class RequestDispatcher : public WscRequestHandler
{
    Q_OBJECT
    Q_DISABLE_COPY(RequestDispatcher)

public:
    //! Standard constructor
    /*! \param kmlSettings KML settings
        \param navigraphDir directory
        \param parent parent Qt object */
    RequestDispatcher(const KmlSettings &kmlSettings, const QString &navigraphDir, QObject *parent); // throw (std::exception)
    //! Destructor.
    ~RequestDispatcher();
    //! Service method called by WebServer
    /*! \param request
        \param response */
    void service(HttpRequest& request, HttpResponse& response);
    //! Terminate the dispatcher
    void terminate();
    //! Settings path/file name.
    /*! \return settings file path */
    const QString getSettingsFile() { return RequestDispatcher::_settingsFile; }
    //! Handler for KML files.
    /*! \return ServiceHandler */
    const WscAircraftKmlWaypoints*  getWscAircraftKmlWaypoints()  { return RequestDispatcher::_wsAircraftKmlWaypoints; }
    //! Handler for JSON.
    /*! \return ServiceHandler */
    const WscAircraftsJson* getWscAircraftsJson() { return RequestDispatcher::_wsAircraftsJson; }
    //! Handler for HTML overview.
    /*! \return ServiceHandler */
    const WscAircraftsHtmlOverview* getWscAircraftsHtmlOverview() { return RequestDispatcher::_wsAircraftsHtml; }
    //! Get the docroot URL, e.g. http://localhost:8080/
    /*! \return docroot URL */
    const static QString getDocrootUrl();
private:
    //! Ini file name (of the web server).
    /*! \return file name */
    const static QString getIniFilename();
    //! refering to NaviGraph data?
    /*! \return NaviGraph path */
    bool isNavigraphPath(const QString &path);
    WscDummyPerson* _wsDummyPerson; /*!< Dummy Person handler */
    WscAircraftsJson* _wsAircraftsJson; /*!< JSON aircraft handler */
    WscAircraftsHtmlOverview* _wsAircraftsHtml; /*!< Aircrafts HTML table handler */
    WscAircraftKmlWaypoints* _wsAircraftKmlWaypoints; /*!< Aircraft KML waypoints handler */
    StaticFileController* _staticFileController; /*!< Static file handler */
    StaticFileController* _wsNavigraph; /*!< For NaviGraph files */
    HttpListener* _listener; /*!< Corresponding listener */
    QString _settingsFile;  /*!< Settings file path/name */
    bool _shutdown; /*!< Dispatcher shutting down */
};
}
#endif // REQUESTDISPATCHER_H
